(define (fast-expt a b)
  (fast-expt-iter a b 0))

(define (fast-expt-iter a b temp)
  (cond ((= b 0) temp)
        ((even? b) (fast-expt-iter (+ a a) (halve b) temp))
        (else (fast-expt-iter a (- b 1) (+ a temp)))))

(define (halve n) (/ n 2))
